function serializeForm(form_name)
{
	var _form = $(form_name);
    var _inputfields  = _form.getElementsByTagName('input');
    var _selectfields = _form.getElementsByTagName('select');

    var url  = "";

    for(var i=0; i < _inputfields.length; i++)
    {
    	var _name  = _inputfields[i].name;
    	var _value = _inputfields[i].value;
    	var _type  = _inputfields[i].type;

    	switch(_type)
    	{
    		case 'text':
                if(_name != '') {
                	url += "&"+_name+"="+_value;
                }
    		    break;

    		case 'hidden':
                if(_name != '') {
                	url += "&"+_name+"="+_value;
                }
    		    break;

    		case 'checkbox':
                if(_name != '' && _inputfields[i].checked == true) {
                	url += "&"+_name+"="+_value;
                }
    		    break;

    		case 'radio':
                if(_name != '' && _inputfields[i].checked) {
                	url += "&"+_name+"="+_value;
                }
    		    break;
    	}
    }

    for(var i=0; i < _selectfields.length; i++)
    {
       var _name  = _selectfields[i].name;
       var _index = _selectfields[i].selectedIndex;
       var _value = _selectfields[i].options[_index].value;

       if(_name != '') {
          url += "&"+_name+"="+_value;
       }
    }

    return url;
}

function isChecked2(isitchecked, f){
	if (isitchecked == true){
		eval("document."+f+".boxchecked.value++;");
	}
	else {
		eval("document."+f+".boxchecked.value--;");
	}
}

function submitParamsForm()
{
   var form_stuff = serializeForm('templateAdmin_container');

   new Ajax("index.php?template_task=update_params"+form_stuff, {
		method: 'post',
		evalScripts: "true",
		update: $('templateAdmin_debug')
	}).request();
}

function addBanner(f)
{
	if(!document.templateAdmin_addBanner.boxchecked.value) {
		alert(lang_tmpl_alert_select_item );
		return false;
	}

	if(!document.templateAdmin_addBanner.banner.value) {
		alert( lang_tmpl_alert_select_banner );
		return false;
	}

	f.submit();
	window.top.setTimeout('new Ajax("index.php?template_task=render_bannermanager", {method: "post",evalScripts: "true",update: window.parent.document.getElementById(\'banner_manager\')}).request();', 700);
}

function updateBanner(f)
{
	if(!document.templateAdmin_addBanner.boxchecked.value) {
			alert( lang_tmpl_alert_select_item );
			return false;
	}

	f.submit();
    window.top.setTimeout('new Ajax("index.php?template_task=render_bannermanager", {method: "post",evalScripts: "true",update: window.parent.document.getElementById(\'banner_manager\')}).request();', 700);
}

function deleteBanner()
{
    if(!document.form_bannermanager.boxchecked.value) {
         alert(lang_tmpl_alert_select_banner);
    }
    else {
       var form_stuff = serializeForm('form_bannermanager');
       new Ajax("index.php?template_task=delete_banner"+form_stuff, {
		        method: 'post',
		        evalScripts: "true",
		        update: $('banner_manager')
	        }).request();}
}